package cn.jobstart.data.job51;

import cn.jobstart.common.FileUtil;
import cn.jobstart.common.StringUtil;
import cn.jobstart.props.FileConfig;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;

/**
 * @author sunke
 * @version 1.0
 * @Description 51job行业
 * @date 2023-11-22 16:07
 */
@Component
public class IndTypeUtil {

    @Resource
    private FileConfig fileConfig;

    private List<IndType> indTypeList;


    public IndTypeUtil() {


    }

    private void init() {

        String data = FileUtil.readInFile(fileConfig.getRoot() + File.separator + "51job" + File.separator + "indtype.js","utf-8");

        indTypeList = JSONArray.parseArray(data, IndType.class);


    }

    public String getIdByName(String name) {
        if (StringUtil.isNullOrEmpty(name)) {
            return null;
        }

        if (StringUtil.isNullOrEmpty(indTypeList)) {
            init();
        }
        if (StringUtil.isNullOrEmpty(indTypeList)) {
            return null;
        }
        for (IndType typeItem : indTypeList) {
            List<IndType> subTypeList = typeItem.getSub();
            if (StringUtil.isNullOrEmpty(subTypeList)) {
                continue;
            }

            for (IndType subItem : subTypeList) {
                if (subItem.getC().indexOf(name)>=0) {
                    return subItem.getId();
                }

            }


        }

        return null;


    }


}
